#ifndef KOD_API_H
#define KOD_API_H

#include "Common/MyString.h"
#include "../KodService/KozTypes.h"

// Definitions for calling KodService.dll
const wchar_t kStrOk[]=L"IDS_OK";
const wchar_t kStrCancel[]=L"IDS_CANCEL";

const wchar_t kStrPwdCaption[]=L"IDS_PWD_CAPTION";
const wchar_t kStrPwdEnter[]=L"IDS_PWD_ENTER";
const wchar_t kStrPwdShow[]=L"IDS_PWD_SHOW";

const wchar_t kStrEncodeCaption[]=L"IDS_ENCODE_CAPTION";
const wchar_t kStrEncodeInfo[]=L"IDS_ENCODE_INFO";

const wchar_t kStrDecodeCaption[]=L"IDS_DECODE_CAPTION";
const wchar_t kStrDecodeInfo[]=L"IDS_DECODE_INFO";
const wchar_t kStrDecodeInputPwd[]=L"IDS_DECODE_INPUT_PWD";

const char kStrKodServiceDLL[] = "KodService.dll";
const char kStrProcSetText[] = "SetTextW";
const char kStrProcPwdDecode[] = "DecodeMyPasswordW";
const char kStrProcPwdEncode[] = "EncodeMyPasswordW";
const char kStrProcPwdGen[] = "GenerateMyPasswordW";
const char kStrProcPwdHash[] = "GetMyPasswordHashW";
const char kStrProcGetMsgID[] = "GetMyMessageID";
const char kStrProcReturnKozSucc[] = "ReturnKozSucc";
const char kStrProcReturnKozFail[] = "ReturnKozFail";
const char kStrProcReturnKozWarn[] = "ReturnKozWarn";
const char kStrProcCheckKozVer[] = "CheckKozVer";

typedef HRESULT(WINAPI *DLLSetTextProc)(wchar_t *var, wchar_t *value);
typedef HRESULT(WINAPI *DLLPwdGenProc)(wchar_t *pwd, int len);
typedef HRESULT(WINAPI *DLLPwdEncodeProc)(wchar_t *pwd, CMyProperty *prop, int silent);
typedef HRESULT(WINAPI *DLLPwdDecodeProc)(wchar_t *pwd, int len, CMyProperty *prop, HWND parent, int silent);
typedef HRESULT(WINAPI *DLLPwdHashProc)(wchar_t *pwd, wchar_t *hash, int len);
typedef HRESULT(WINAPI *DLLGetMsgIDProc)();
typedef HRESULT(WINAPI *DLLReturnKozRes)(int handle, int id);
typedef HRESULT(WINAPI *DLLCheckKozVer)(wchar_t *ver);

class CKodLibrary
{
private:
  HINSTANCE _hinstDLL;
  DLLSetTextProc _procSetText;
  DLLPwdGenProc _procPwdGen;
  DLLPwdEncodeProc _procPwdEncode;
  DLLPwdDecodeProc _procPwdDecode;
  DLLPwdHashProc _procPwdHash;
  DLLGetMsgIDProc _procGetMsgID;
  DLLReturnKozRes _procReturnKozSucc;
  DLLReturnKozRes _procReturnKozFail;
  DLLReturnKozRes _procReturnKozWarn;
  DLLCheckKozVer _procCheckKozVer;

  HRESULT SetLangString(wchar_t *var, wchar_t *value);
public:
  CKodLibrary();
  ~CKodLibrary();

  void SetLocale();

  HRESULT PwdGen(wchar_t *pwd, int len);
  HRESULT PwdEncode(wchar_t *pwd, CMyProperty *prop, bool silent);
  HRESULT PwdDecode(wchar_t *pwd, int len, CMyProperty *prop, HWND parent, bool silent);
  HRESULT PwdHash(wchar_t *pwd, wchar_t *hash, int len);
  HRESULT GetMessageID();
  HRESULT ReturnKozSucc(int handle, int id);
  HRESULT ReturnKozFail(int handle, int id);
  HRESULT ReturnKozWarn(int handle, int id);
  HRESULT CheckKozVer(wchar_t *ver);
};

// Wrapper funtions for using CKodLibrary
HRESULT GenerateMyPassword(UString &pwd);
HRESULT EncodeMyPassword(UString &pwd, CMyProperty &prop);
HRESULT DecodeMyPassword(UString &pwd, CMyProperty &prop, HWND parent);
UString GetMyPasswordHash(UString &pwd);
UINT GetMyKodMessageID();
HRESULT ReturnMyKozSucc(int handle, int id);
HRESULT ReturnMyKozFail(int handle, int id);
HRESULT ReturnMyKozWarn(int handle, int id);
HRESULT CheckMyKozVer(wchar_t *ver);

#endif //!KOD_API_H